home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 23 / CU Amiga - Super CD-ROM 23 (June 1998).iso / CUCD / Programming / OUI / locale.cc < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  2.7 KB  |  113 lines

  1. // $Id: locale.cc 1.3 1997/09/17 08:16:17 dlorre Exp dlorre $
  2. #include <exec/types.h>
  3. #include <dos/dos.h>
  4. #include "locale.h"
  5.  
  6. #if defined( LOCALISE )
  7. #include <stdio.h>
  8. #include <string.h>
  9. #endif
  10.  
  11. #if defined( LOCALISE )
  12. #include <proto/dos.h>
  13. #endif
  14. #include <proto/locale.h>
  15. #include <mydebug.h>
  16.  
  17. #if defined( LOCALISE )
  18. static char ch[255] ;
  19. static char cdfilename[255] ;
  20. static char ctfilename[255] ;
  21. static BPTR fh ;
  22.  
  23. static void AppendString(STRPTR def, STRPTR string, int id, STRPTR desc, catalog *lc)
  24. {
  25. int l ;
  26.     sprintf(ch, lc->catname) ;
  27.     l = strlen(ch) ;
  28.     if (l > 8 && !strcmp(ch+l-8, ".catalog")) {
  29.         ch[l-8] = '\0' ;
  30.     }
  31.     sprintf(cdfilename, "RAM:%s.cd", ch) ;
  32.     sprintf(ctfilename, "RAM:%s_%s.ct", ch, lc->langname) ;
  33.  
  34.     if (fh = Open(cdfilename, MODE_READWRITE)) {
  35.         if (Seek(fh, 0, OFFSET_END) != -1) {
  36.             if (id != -1)
  37.                 sprintf(ch, "%s (%ld//)\n%s\n", desc, id, def) ;
  38.             else
  39.                 sprintf(ch, "%s (//)\n%s\n", desc, def) ;
  40.             Write(fh, ch, strlen(ch)) ;
  41.             Flush(fh) ;
  42.         }
  43.         Close(fh) ;
  44.     }
  45.     if (fh = Open(ctfilename, MODE_READWRITE)) {
  46.         if (Seek(fh, 0, OFFSET_END) != -1) {
  47.             sprintf(ch, "%s\n%s\n;%s\n;\n", desc, string, def) ;
  48.             Write(fh, ch, strlen(ch)) ;
  49.             Flush(fh) ;
  50.         }
  51.         Close(fh) ;
  52.     }
  53. }
  54. #endif
  55.  
  56.  
  57. catalog::catalog(char *name, char *deflang, char *lang) : locnum(0)
  58. {
  59.     if (LocaleBase) {
  60. #if defined( LOCALISE )
  61. int l ;
  62.     strcpy(catname, name) ;
  63.     strcpy(langname, lang ? lang : "default") ;
  64.     sprintf(ch, catname) ;
  65.     l = strlen(ch) ;
  66.     if (l > 8 && !strcmp(ch+l-8, ".catalog")) {
  67.         ch[l-8] = '\0' ;
  68.     }
  69.     sprintf(cdfilename, "RAM:%s.cd", ch) ;
  70.     sprintf(ctfilename, "RAM:%s_%s.ct", ch, langname) ;
  71.     if (fh = Open(cdfilename, MODE_NEWFILE))
  72.         Close(fh) ;
  73.     if (fh = Open(ctfilename, MODE_NEWFILE))
  74.         Close(fh) ;
  75.  
  76. #endif
  77.         cat = OpenCatalog(NULL, name,
  78.             OC_BuiltInLanguage, deflang,
  79.             OC_Language,        lang,
  80.             TAG_DONE) ;
  81.     }
  82.     else
  83.         cat = NULL ;
  84. }
  85. catalog::~catalog() { if (LocaleBase) CloseCatalog(cat) ; }
  86.  
  87.  
  88. #ifdef LOCALISE
  89. lstring::lstring(catalog *lc, char *def, char *desc, int id)
  90. {
  91.     if (lc && LocaleBase) {
  92.         if (id != -1) lc->locnum  = id ;
  93.         string = GetCatalogStr(lc->cat, lc->locnum, def) ;
  94.         AppendString(def, string, id, desc, lc) ;
  95.         lc->locnum++ ;
  96.     }
  97.     else
  98.         string = def ;
  99. }
  100. #else
  101. lstring::lstring(catalog *lc, char *def, int id)
  102. {
  103.     if (lc && LocaleBase) {
  104.         if (id != -1) lc->locnum  = id ;
  105.         string = GetCatalogStr(lc->cat, lc->locnum, def) ;
  106.         lc->locnum++ ;
  107.     }
  108.     else
  109.         string = def ;
  110. }
  111.  
  112. #endif
  113.